package main

import (
	"fmt"
	"math/big"
	"reflect"
	"strconv"
)

func main() {
	var v1 int8 = 10
	var v2 int16 = 18

	v3 := int16(v1) + v2

	fmt.Println(v3, reflect.TypeOf(v3))

	v4 := 10
	result := strconv.Itoa(v4)
	fmt.Println("result=", result, reflect.TypeOf(result))

	v5, _ := strconv.Atoi(result)
	fmt.Println("v5=", v5, reflect.TypeOf(v5))

	// 整形转换为二进制..八进制..十六进制..
	r1 := strconv.FormatInt(int64(10), 2)
	fmt.Println(r1, reflect.TypeOf(r1))

	r2 := strconv.FormatInt(int64(10), 8)
	fmt.Println(r2, reflect.TypeOf(r2))

	r3 := strconv.FormatInt(int64(10), 16)
	fmt.Println(r3, reflect.TypeOf(r3))

	// 其他进制按照规定要求转换为int，最终结果都是int64类型
	data := "010111010"
	i, err := strconv.ParseInt(data, 2, 10)
	fmt.Println(i, err, reflect.TypeOf(i))

	// 练习 将一个二进制的数转换为 十六进制

	// a. 转换为十进制
	result10, err := strconv.ParseInt("10010001010", 2, 0)
	fmt.Println(result10, err, reflect.TypeOf(result10))

	// b. 转换为十六进制
	formatInt := strconv.FormatInt(result10, 16)
	fmt.Println(formatInt, err, reflect.TypeOf(formatInt))

	n1 := new(big.Int)
	n1.SetInt64(100)

	n2 := big.NewInt(200)

	result1 := new(big.Int)
	//var result1 big.Int
	fmt.Println(result1, reflect.TypeOf(result1))
	fmt.Println(result1.String(), reflect.TypeOf(result1.String()))
	fmt.Println("------------------")

	add := result1.Add(n1, n2)
	fmt.Println(add, reflect.TypeOf(add))

	fmt.Println("------------------")
	fmt.Println(result1, reflect.TypeOf(result1))
	fmt.Println(result1.Int64(), reflect.TypeOf(result1.Int64()))
	fmt.Println(result1.String(), reflect.TypeOf(result1.String()))

}
